### --- Test setup ---
if(FALSE) {
	## Not really needed, but can be handy when writing tests
	library("RUnit")
	library("unsupervisedMicroarray")
	
}

#data for tests
library(rda)
data(brain)
data(iris)
data(wine)
irDat <- as.matrix(iris[,-5])
irC <- as.numeric(iris[,5])

bx <- brain.x[,70:100]
by <- brain.y
mm<-(matrix(runif(100),ncol=5))
mmC <- c(rep(1,10),rep(2,10))

scoreS <-function(scoreObj,inputSet,clusters){
	indexx <- ScoreSet(scoreObj,inputSet,clusters)
	
	checkTrue(is.numeric(indexx))
	
	#checkTrue(indexx <=1)
	print("INDEX: ");print(indexx)
}
scoreF <-function(scoreObj,inputSet,clusters){
	indexx <- ScoreSet(scoreObj,inputSet,clusters)
	
	checkTrue(is.numeric(indexx))
	checkTrue(indexx >=-1)
	checkTrue(indexx <=1)
	print("INDEX: ");print(indexx)
}


test.clustering_ParamHclust <- function(){
	
	phcl <- new("HierParamClusterAlg",3)
	
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}
#
#
test.clustering_NonParamHclust <- function(){
	
	indO <- new("SilhIClusterScore")
	phcl <- new("HierNonParamClusterAlg",indO)
	Rprof()
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	Rprof(NULL)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}
#
#
#
test.clustering_ParamFCMbased_FCM <- function(){
	

	phcl <- new("FCMParamClusterAlg",3)
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	print("IRIS CLust")
	print(clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}

test.clustering_ParamFCMbased_GK <- function(){
	
	
	phcl <- new("FCMParamClusterAlg",3,method="GK")
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	print("IRIS CLust")
	print(clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))

	print("Wine")
	clusters <- clusterize(phcl,wine)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(wine$Y))
	
	print("WARNINGS!!!!!!!!!!!!!!!!!!!!!!!!!")
	warnings()
}
###
test.clustering_ParamFCMbased_GKN <- function(){
	
	
	phcl <- new("FCMParamClusterAlg",3,method="GKN",dnoise=0.8)
	Rprof("GKNprof.out")
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	Rprof(NULL)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	print("IRIS CLust")
	print(clusters)
	
	print("Brain test")
	Rprof("GKNprof2.out")
	clusters <- clusterize(phcl,list(X=bx))
	Rprof(NULL)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	#Rprof("GKNprof3.out")
	clusters <- clusterize(phcl,list(X=mm))
	#Rprof(NULL)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
#	
	print("Wine")
	clusters <- clusterize(phcl,wine)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(wine$Y))
	print("WARNINGS!!!!!!!!!!!!!!!!!!!!!!!!!")
	warnings()
}
#
test.clustering_NonParamFCMbased_GK <- function(){
	
	indO <- new("SilhIClusterScore")
	phcl <- new("FCMNonParamClusterAlg",indO,method="GK")
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
	print("Wine")
	clusters <- clusterize(phcl,wine)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(wine$Y))
	
	print("WARNINGS:")
	warnings()
}
#
test.clustering_NonParamFCMbased_GKN <- function(){
	
	indO <- new("SilhIClusterScore")
	phcl <- new("FCMNonParamClusterAlg",indO,method="GKN")
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
	print("Wine")
	clusters <- clusterize(phcl,wine)
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(wine$Y))
}
test.clustering_NonParamFCMbased_FCM <- function(){
	
	indO <- new("SilhIClusterScore")
	phcl <- new("FCMNonParamClusterAlg",indO)
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}
test.clustering_NonParamFCMbased_NC <- function(){
	print("Initialize Index")
	indO <- new("SilhIClusterScore")
	print("initialize Clusterizer")
	phcl <- new("FCMNonParamClusterAlg",indO,method="NC")
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	print("After cLust")
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}
test.clustering_NonParamDBScan <- function(){
	
	indO <- new("SilhIClusterScore")
	phcl <- new("DBScanNonParamClusterAlg",indO)
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	
	indO <- new("IIClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	indO <- new("HARandEClusterScore")
	scoreF(indO,list(X=irDat,Y=irC),clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
}
##
test.clustering_ParamDBScan<- function(){
	
	
	phcl <- new("DBScanParamClusterAlg")
	
	print("Iris test")
	clusters <- clusterize(phcl,list(X=irDat))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(irC))
	print("IRIS CLust")
	print(clusters)
	
	print("Brain test")
	clusters <- clusterize(phcl,list(X=bx))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(by))
	
	print("Random test")
	clusters <- clusterize(phcl,list(X=mm))
	checkTrue(class(clusters)=="numeric")
	checkTrue(length(clusters)==length(mmC))
#	
	print("WARNINGS!!!!!!!!!!!!!!!!!!!!!!!!!")
	warnings()
}
